package com.re6g3y.game.core;


import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.Vector2;

public class InputEven implements InputProcessor {
    final static private float scaleBound =10;
    final static private Vector2 nowDragPoint=new Vector2();
    OrthographicCamera camera;
    public InputEven(OrthographicCamera camera){
        this.camera=camera;
        Gdx.input.setInputProcessor(this);
    }
    @Override
    public boolean keyDown (int keycode) {
        return false;
    }
    @Override
    public boolean keyUp (int keycode) {
        return false;
    }
    @Override
    public boolean keyTyped (char character) {
        return false;
    }
    @Override
    public boolean touchDown (int x, int y, int pointer, int button) {
        if(pointer==0)nowDragPoint.set(x,y);
        return false;
    }
    @Override
    public boolean touchUp (int x, int y, int pointer, int button) {
        return false;
    }
    @Override
    public boolean touchDragged (int x, int y, int pointer) {
        if(pointer==0) {
            camera.position.add(-(x-nowDragPoint.x) * camera.zoom, (y-nowDragPoint.y)* camera.zoom, 0);
            nowDragPoint.set(x,y);
        }
        return false;
    }
    @Override
    public boolean mouseMoved (int x, int y) {
        return false;
    }
    @Override
    public boolean scrolled (int amount) {
        float tarx=Gdx.input.getX()-Gdx.graphics.getWidth()/2;
        float tary=Gdx.input.getY()-Gdx.graphics.getHeight()/2;
        float scl=(float) Math.pow(0.90f,amount);

        float nowscl=camera.zoom/scl;
        if(nowscl>1/ scaleBound&&nowscl<scaleBound){
            camera.zoom = nowscl;
            camera.position.add(-tarx*(1-scl) * camera.zoom, tary*(1-scl)* camera.zoom, 0);
        }
        return false;
    }
}